<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="date"
          placeholder="请选择"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="行政区" prop="assetName">
        <el-select
          v-model="queryParams.assetName"
          placeholder="请选择"
          filterable
          clearable
        >
          <el-option
            v-for="users in listUsers"
            :key="users.value"
            :label="users.label"
            :value="users.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="小区" prop="assetCode">
        <el-select
          v-model="queryParams.assetCode"
          placeholder="请选择"
          filterable
          clearable
        >
          <el-option
            v-for="users in listUsers"
            :key="users.value"
            :label="users.label"
            :value="users.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="assetList">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->

      <el-table-column label="时间" align="center" prop="time" />
      <el-table-column label="行政区" align="center" prop="area" />
      <el-table-column label="小区" align="center" prop="assetName" />
      <el-table-column
        label="监测点"
        align="center"
        prop="assetCode"
        width="220"
      />
      <!--      <el-table-column label="统一编码" align="center" prop="gs1Code" :sort-orders="['descending','ascending']" sortable="custom"/>-->
      <!-- <el-table-column
        label="设备类型"
        align="center"
        prop="assetClassificationName"
      /> -->
      <el-table-column label="蚁害情况" align="center">
        <template slot-scope="scope">
          <el-tag :type="scope.row.number === '1' ? 'success' : 'danger'">
            {{ scope.row.number === "1" ? "无蚁" : "有蚁" }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="230"
      >
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="seedetail(scope.row)"
            >查看详情
          </el-button>
          <!-- <el-button
            size="mini"
            type="text"
            style="color: red"
            @click="handleDelete(scope.row)"
            >删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      class="pagination-container"
    />
  </div>
</template>

<script>
import {
  listAsset,
  getAsset,
  delAsset,
  addAsset,
  updateAsset,
  listassetClassification,
} from "@/api/manage/asset";
import { getPersonnelList } from "@/api/manage/personnel";
import { getDepartmentList } from "@/api/manage/department";
// import { treeSelect } from "@/api/system/dept";
import { getUserlist } from "@/api/system/user";
// import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "Asset",
  dicts: [
    // "asset_unit",
    // "asset_acquisition_method",
    // "asset_use_status",
    // "asset_use_direction",
  ],
  // components: { Treeselect, printDSVue },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产信息表格数据
      assetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 资产分类树桩选项
      assetClassificationOptions: [],
      // 启用日期时间范围
      daterangeStartDate: [],
      // 部门树桩选项
      deptOptions: [],
      // 归属账号下拉选项
      listUsers: [
        {
          value: "行政区一",
          label: "行政区一",
        },
        {
          value: "行政区二",
          label: "行政区二",
        },
        {
          value: "行政区三",
          label: "行政区三",
        },
      ],
      // 是否显示二维码弹出层
      getCodeUrlOpen: false,
      // 打印弹出层
      openPrint: false,
      assets: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        time: "",
        assetName: null,
        assetCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        assetName: [
          { required: true, message: "资产名称不能为空", trigger: "blur" },
        ],
      },
      // 导入结果弹出框
      resultVisible: false,
      // 人员下拉
      personnels: [],
      // 部门下拉
      departments: [],
    };
  },
  created() {
    this.getList();
    // this.getListAssetAll();
    // this.getTreeselect();
    // this.getUser();
    // this.getTemplateList();
    // this.getDepartment();
    // this.getPersonnel();
  },
  methods: {
    seedetail(row) {
      console.log(row);
    },
    /*人员下拉选项*/
    getDepartment() {
      getDepartmentList().then((response) => {
        this.departments = response.rows;
      });
    },
    /*人员下拉选项*/
    getPersonnel() {
      getPersonnelList().then((response) => {
        this.personnels = response.rows;
      });
    },

    /** 二维码按钮操作 */
    getCodeUrl(row) {
      this.reset();
      this.getCodeUrlOpen = true;
      this.title = "rfid编码（" + row.rfidCode + ")";
      // 生成二维码
      this.$nextTick(function () {
        console.log(document.getElementById("qrCodeUrl"));
        document.getElementById("qrCodeUrl").innerHTML = "";
        let qrCodeUrl = new QRCode("qrCodeUrl", {
          width: 200,
          height: 200,
          text: row.rfidCode,
          colorDark: "#000000",
          colorLight: "#fff",
        });
      });
    },
    /*归属账号下拉选项*/
    getUser() {
      getUserlist().then((response) => {
        this.listUsers = response.rows;
      });
    },
    /*部门树桩选项*/
    getTreeselect() {
      treeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    /*资产分类树桩选项*/
    getListAssetAll() {
      listassetClassification().then((response) => {
        this.assetClassificationOptions = response.data;
      });
    },
    /** 查询资产信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      setTimeout(() => {
        this.assetList = [
          {
            time: "2025-01-01",
            area: "行政区一",
            assetName: "行政区一",
            assetCode: "001",
            assetClassificationName: "摄像头",
            number: "1",
            rfidCode: "RFID001",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "002",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID002",
          },
          {
            time: "2025-01-01",
            area: "行政区一",
            assetName: "行政区一",
            assetCode: "003",
            assetClassificationName: "监控设备",
            number: "1",
            rfidCode: "RFID003",
          },
          {
            time: "2025-01-01",
            area: "行政区三",
            assetName: "行政区三",
            assetCode: "004",
            assetClassificationName: "摄像头",
            number: "1",
            rfidCode: "RFID004",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
          {
            time: "2025-01-01",
            area: "行政区二",
            assetName: "行政区二",
            assetCode: "005",
            assetClassificationName: "门禁",
            number: "0",
            rfidCode: "RFID005",
          },
        ];
        this.total = this.assetList.length;
        this.loading = false;
      }, 2000);
      // listAsset(this.queryParams).then((response) => {
      //   this.assetList = response.rows;
      //   this.total = response.total;
      //   this.loading = false;
      // });
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        assetName: null,
        assetCode: null,
      };
      this.resetForm("form");
      this.openPrint = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.reset();
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset();
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除资产信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delAsset(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
.el-collapse .el-collapse-item__header {
  font-size: 16px;
  font-weight: bold;
}

.pagination-container {
  margin-top: 20px;
  width: 100%;
}

.pagination-container .el-pagination {
  display: flex;
  justify-content: center;
  width: 100%;
}
</style>
